package com.mars.admin.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.mars.admin.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.mars.admin.modules.sys.entity.SensorBattrystatusEntity;
import com.mars.admin.modules.sys.service.SensorBattrystatusService;
import com.mars.admin.common.utils.PageUtils;
import com.mars.admin.common.utils.R;



/**
 * 传感器电量信息
 *
 * @author lrj
 * @email lrjchina88@gmail.com
 * @date 2018-08-10 05:14:32
 */
@RestController
@RequestMapping("sys/sensorbattrystatus")
public class SensorBattrystatusController {
    @Autowired
    private SensorBattrystatusService sensorBattrystatusService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:sensorbattrystatus:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sensorBattrystatusService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:sensorbattrystatus:info")
    public R info(@PathVariable("id") Integer id){
        SensorBattrystatusEntity sensorBattrystatus = sensorBattrystatusService.selectById(id);

        return R.ok().put("sensorBattrystatus", sensorBattrystatus);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:sensorbattrystatus:save")
    public R save(@RequestBody SensorBattrystatusEntity sensorBattrystatus){
        sensorBattrystatusService.insert(sensorBattrystatus);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:sensorbattrystatus:update")
    public R update(@RequestBody SensorBattrystatusEntity sensorBattrystatus){
        ValidatorUtils.validateEntity(sensorBattrystatus);
        sensorBattrystatusService.updateAllColumnById(sensorBattrystatus);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:sensorbattrystatus:delete")
    public R delete(@RequestBody Integer[] ids){
        sensorBattrystatusService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/generatecharge")
    public R generateCharge(){
        sensorBattrystatusService.generatecharge(new Date());

        return R.ok();
    }

    @RequestMapping("/generateneedfix")
    public R generateNeedfix(){
        sensorBattrystatusService.generatefix(new Date());

        return R.ok();
    }

}
